Skip to content

BUG: fix to_datetime(dti, utc=True) #27733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 5, 2019
Merged

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

ATM to_datetime(naive_dti, utc=True) returns naive incorrect, same for naive DatetimeArray

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs a whatsnew entry

@jbrockmendel
Copy link
Member Author

updated with whatsnew and suggested edits

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. small comments, ping on green.

@@ -31,7 +31,7 @@ Categorical

Datetimelike
^^^^^^^^^^^^

- Bug in :func:`to_datetime` where passing a timezone-naive :class:`DatetimeArray` or :class:`DatetimeIndex` and utc=True would incorrectly return a timezone-naive result (:issue:`27733`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put utc=True in double-back quotes

@jreback jreback added Datetime Datetime data dtype Timezones Timezone data dtype labels Aug 4, 2019
@jreback jreback added this to the 0.25.1 milestone Aug 4, 2019
@@ -334,6 +334,9 @@ def _convert_listlike_datetimes(
return DatetimeIndex(arg, tz=tz, name=name)
except ValueError:
pass
elif tz:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would fail if a user passes to_datetime(np.array([...], dtype='datetime64[ns]'), utc=True)?

I was thinking more:

if box:
    if not isinstance(arg, (DatetimeArray, ...)):
        ....
    elif tz:
        ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> arr = np.arange(2).astype('datetime64[ns]')
>>> to_datetime(arr, utc=True)
DatetimeIndex(['1970-01-01 00:00:00+00:00', '1970-01-01 00:00:00.000000001+00:00'], dtype='datetime64[ns, UTC]', freq=None)

or are you suggesting that this is wrong because box=True was not passed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! It does work. box=True is the default so this looks correct.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, over to @mroeschke

@mroeschke mroeschke merged commit 61819ab into pandas-dev:master Aug 5, 2019
@mroeschke
Copy link
Member

Thanks @jbrockmendel

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Aug 5, 2019
@jbrockmendel jbrockmendel deleted the todt branch August 5, 2019 21:09
quintusdias pushed a commit to quintusdias/pandas_dev that referenced this pull request Aug 16, 2019
* BUG: fix to_datetime(dti, utc=True)

* whatsnew, suggested edits

* parametrize

* backquotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants